package com.zephyr.vchcenter.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import org.apache.log4j.Logger;

import com.zephyr.vchcenter.bean.Voucher;
import com.zephyr.vchcenter.bean.VoucherTemp;
import com.zephyr.vchcenter.dao.IBaseDao;
import com.zephyr.vchcenter.dao.IVoucherDao;
import com.zephyr.vchcenter.dao.impl.VoucherDaoImpl;
import com.zephyr.vchcenter.helper.SpringHelper;
import com.zephyr.vchcenter.service.ICreateProcessService;
import com.zephyr.vchcenter.service.IVoucherService;
import com.zephyr.vchcenter.util.XmlParseUtil;

public class VoucherServiceImpl implements IVoucherService {

	private static Logger log = Logger.getLogger(VoucherServiceImpl.class);
	private IVoucherDao voucherDao;

	// private XmlInfoParser xmlParse = new XmlInfoParser();

	public VoucherServiceImpl() {
	};

	public VoucherServiceImpl(IVoucherDao voucherDao) {
		this.voucherDao = voucherDao;
	}


	public List listVoucherInstances(Map<String, String> map) {

		Voucher voucher = getVoucherInstance(map);
		log.debug(".......");
		List<Voucher> res = new Vector<Voucher>();
		if (voucher.getIdstate()!=null || voucher.getChkstate() != null) {
			res = voucherDao.findByCondition(voucher);
		} else {
			List<Object> list = voucherDao.findByExample(voucher);
            System.out.println(list.size()+"pppp");
			for (Object obj : list) {
				Voucher vou = (Voucher) obj;
				res.add(vou);
			}
		}
		log.debug("size of listInstance...." + res.size());
		if (res.size() == 0) {
			return null;
		}
		log.debug(res.size()+"-->-->");
		return res;
		// System.out.println("size of listInstance...." + list.size());
		// String resultXML = xmlParse.buildXmlStringWithInstance(res);//��Ͻ��
		// return resultXML;
	}



	private Voucher getVoucherInstance(Map<String, String> map) {

		Voucher voucher = new Voucher();


		if (map.get("accno") != null && !"".equals(map.get("accno"))) {

			voucher.setAccno(map.get("accno"));
		}
		if (map.get("vchno") != null && !"".equals(map.get("vchno"))) {
			voucher.setVchno(map.get("vchno"));
		}
		if (map.get("subno") != null && !"".equals(map.get("subno"))) {
			voucher.setSubno(map.get("subno"));
		}
		if (map.get("chkstate") != null && !"".equals(map.get("chkstate"))) {
			voucher.setChkstate(map.get("chkstate"));
		}
		if (map.get("idstate") != null && !"".equals(map.get("idstate"))) {
			voucher.setIdstate(map.get("idstate"));
		}
		if (map.get("tallytype") != null && !"".equals(map.get("tallytype"))) {
			voucher.setTallytype(map.get("tallytype"));
		}
		if (map.get("amount") != null && !"".equals(map.get("amount"))) {
			voucher.setAmount(map.get("amount"));
		}
		
		log.debug(voucher.getAccno() + "---------");
		log.debug(voucher.getChkstate() + "--------------");
		log.debug(voucher.getIdstate()+"-------------");
		return voucher;
	}

	public List listBaseObject(Map<String, String> map) {

		Voucher voucher = getVoucherInstance(map);
		log.debug(voucher.getIdstate()+"*******");
		List<Voucher> res = voucherDao.findByCondition(voucher);
		return res;
	}

	public Map<String,String> Z_BAPI_ACCOUNT_INFO(String accno) {
		Map map=new HashMap<String,String>();
		log.debug("正在获取账户信息");
		log.debug(accno);
	    
		String accnName=accno.length()>6?"北京紫枫科技":"上海XX科技";
		String custId=accno.length()>6?"0001":"0002";
		map.put("custId", custId);
		map.put("accName", accnName);
		map.put("amount", "111,1111");
		map.put("leavedAmount", "111,1100");
		map.put("accState", "3");
		return map;
	}

	public Map<String,String> Z_BAPI_BP_GET_ORG_DETAIL(String custId) {
		Map map=new HashMap<String,String>();
		log.debug("正在获取客户信息");
		String connector=custId.equals("0001")?"黄兵":"韩敏";
		map.put("custState", "1");
		map.put("openDate", "2009-01-06");
		map.put("tel", "13466347403");
		map.put("connector", connector);
		return map;
	}

	public Integer VerifyPaycode(String accno, String vchpwd, String vchtype) {
		
		return 1;
	}
	
	public String Z_BAPI_BP_SIGN_PROD_GETDETAIL(String accno) {
		log.debug(accno.length());
	    String renturnval="1";
		if(accno.length()>10){
			log.debug("财政户");
			renturnval="2";
	    }
		return renturnval;
	}



}
